﻿using SXT.Party.Utility;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace ZHDJ.MobileInterface
{
    /// <summary>
    /// GDInterfaceService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消注释以下行。 
    // [System.Web.Script.Services.ScriptService]
    public class GDInterfaceService : System.Web.Services.WebService
    {
        private string BranchID = "9C717F5509C543C78A3B815CFAA4E066"; 

        /// <summary>
        /// 党员信息
        /// </summary>
        /// <param name="systemID"></param>
        /// <returns></returns>
        [WebMethod]
        public DataSet GetMembersInfo(string systemID)
        {
            if (!InterfaceHelper.GDValidate(systemID))
                return null;

            return InterfaceHelper.GetGDMembersInfo(BranchID);
        }

        /// <summary>
        /// 组织信息
        /// </summary>
        /// <param name="systemID"></param>
        /// <returns></returns>
        [WebMethod]
        public DataSet GetBranchInfo(string systemID)
        {
            if (!InterfaceHelper.GDValidate(systemID))
                return null;

            return InterfaceHelper.GetGDBranchInfo(BranchID);
        }

        /// <summary>
        /// 组织动态——支部活动
        /// </summary>
        /// <param name="systemID"></param>
        /// <returns></returns>
        [WebMethod]
        public DataSet GetBranchActivitie(string systemID)
        {
            if (!InterfaceHelper.GDValidate(systemID))
                return null;

            return InterfaceHelper.GetGDBranchActivitie(BranchID);
        }

        /// <summary>
        /// 志愿服务——志愿活动召集
        /// </summary>
        /// <param name="systemID"></param>
        /// <returns></returns>
        [WebMethod]
        public DataSet GetVSActivity(string systemID)
        {
            if (!InterfaceHelper.GDValidate(systemID))
                return null;

            DataSet ds = InterfaceHelper.GetGDVSActivity(BranchID);

            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                DataSet dsTemp;
                string strTemp = "";
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    dsTemp = InterfaceHelper.GetGDVSActivityMember(dr["ActivityID"].ToString());

                    strTemp = "";
                    if (dsTemp != null && dsTemp.Tables[0].Rows.Count > 0)
                    {
                        foreach (DataRow item in dsTemp.Tables[0].Rows)
                        {
                            if (string.IsNullOrEmpty(strTemp))
                            {
                                strTemp += item["UserName"].ToString();
                            }
                            else
                            {
                                strTemp += "," + item["UserName"].ToString();
                            }
                        }
                        dr["JoinMembers"] = strTemp;
                    }
                }
                ds.Tables[0].Columns.Remove("ActivityID");
            }

            return ds;
        }

        /// <summary>
        /// 书记讲话
        /// </summary>
        /// <param name="systemID"></param>
        /// <returns></returns>
        [WebMethod]
        public DataSet GetLeaderSpeak(string systemID)
        {
            if (!InterfaceHelper.GDValidate(systemID))
                return null;

            return InterfaceHelper.GetGDLeaderSpeak();
        }

        /// <summary>
        /// 党代表直通车——党代表信息
        /// </summary>
        /// <param name="systemID"></param>
        /// <returns></returns>
        [WebMethod]
        public DataSet GetPartyDeputy(string systemID)
        {
            if (!InterfaceHelper.GDValidate(systemID))
                return null;

            DataSet ds = InterfaceHelper.GetGDPartyDeputy("BA10FD2DF0734AB8A74C1B1F2FCEDF04");

            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    if(!string.IsNullOrEmpty(Convert.ToString(dr["ImageUrl"])))
                        dr["ImageUrl"] = CommonUtils.GetSmallImg(CommonUtils.AppAddress + SXT.Utility.FileServer.QueryFileUrl(dr["ImageUrl"].ToString()));
                }
            }

            return ds;
        }

        /// <summary>
        /// 党代表直通车——活动公告
        /// </summary>
        /// <param name="systemID"></param>
        /// <returns></returns>
        [WebMethod]
        public DataSet GetDeputyMeetNotices(string systemID)
        {
            if (!InterfaceHelper.GDValidate(systemID))
                return null;

            return InterfaceHelper.GetGDDeputyMeetNotices("BA10FD2DF0734AB8A74C1B1F2FCEDF04");
        }

        /// <summary>
        /// 党代表直通车——预约党代表
        /// </summary>
        /// <param name="systemID"></param>
        /// <returns></returns>
        [WebMethod]
        public DataSet GetMeetingWithData(string systemID)
        {
            if (!InterfaceHelper.GDValidate(systemID))
                return null;

            return InterfaceHelper.GetGDMeetingWithData("BA10FD2DF0734AB8A74C1B1F2FCEDF04");
        }

        /// <summary>
        /// 党代表直通车——心声传递
        /// </summary>
        /// <param name="systemID"></param>
        /// <returns></returns>
        [WebMethod]
        public DataSet GetPartySuggestion(string systemID)
        {
            if (!InterfaceHelper.GDValidate(systemID))
                return null;

            return InterfaceHelper.GetGDPartySuggestion("BA10FD2DF0734AB8A74C1B1F2FCEDF04");
        }

        /// <summary>
        /// 支援品牌
        /// </summary>
        /// <param name="systemID"></param>
        /// <returns></returns>
        [WebMethod]
        public DataSet GetVSBrandManage(string systemID)
        {
            if (!InterfaceHelper.GDValidate(systemID))
                return null;

            DataSet ds = InterfaceHelper.GetGDVSBrandManage(BranchID);

            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    if (!string.IsNullOrEmpty(Convert.ToString(dr["Participants"])))
                        dr["Participants"] = SXT.Utility.Business.Picker.GetPickerText("tblPartyOrgMembers", "UserName", "LoginID", dr["Participants"].ToString());
                     
                    if (!string.IsNullOrEmpty(Convert.ToString(dr["imageUrl"])))
                        dr["imageUrl"] = CommonUtils.AppAddress + SXT.Utility.FileServer.QueryFileUrl(dr["imageUrl"].ToString());
                }
            }
            return ds;
        }

        /// <summary>
        /// 志愿者心语
        /// </summary>
        /// <param name="systemID"></param>
        /// <returns></returns>
        [WebMethod]
        public DataSet GetPartyVSTruth(string systemID)
        {
            if (!InterfaceHelper.GDValidate(systemID))
                return null;

            return InterfaceHelper.GetGDPartyVSTruth(BranchID); 
        }
    } 
}
